#include "head.h"

int init_status(status_t* status,int thread_num){

    status->thread_num = thread_num;
 
    status->thread_ids = (pthread_t*)malloc(thread_num * sizeof(pthread_t));
    if (!status->thread_ids)
    {
        ERR_LOG("thread error");
        return -1;
    }
    //不要写 if (!pthread_mutex_init(...))，因为返回 0 表示成功，非 0 才是失败。
    
    if (pthread_mutex_init(&status->mutex,NULL) != 0)
    {
        free(status->thread_ids);
        ERR_LOG("pthread_mutex_init error");
        return -1;
    }
    if (pthread_cond_init(&status->cond,NULL) != 0)
    {
        free(status->thread_ids);
        pthread_mutex_destroy(&status->mutex);
        ERR_LOG("pthread_cond_init error");
        return -3;
    }

    memset(&status->queue,0,sizeof(queue_t));


}